﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.SheepMomPergnantCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.DataImp;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepMomPergnantHandler
{
    public class SheepMomPergnantAddCommandHandler : IRequestHandler<SheepMomPergnantAddCommand, Results<int>>
    {
        private readonly ISheepMomPergnantService _sheepMomPergnantService;
        private readonly IMapper _mapper;
        public SheepMomPergnantAddCommandHandler(ISheepMomPergnantService sheepMomPergnantService, IMapper mapper)
        {
            _sheepMomPergnantService = sheepMomPergnantService;
            _mapper = mapper;
        }

        public async Task<Results<int>> Handle(SheepMomPergnantAddCommand request, CancellationToken cancellationToken)
        {
            var result = _mapper.Map<List<SheepMomPergnant>>(request.PergnantList);

            return Results<int>.DataResult(await _sheepMomPergnantService.AddSheepMomPergnant(result));
        }
    }
}
